import cmath
import math
import sys


def get_float(msg, allow_zero):
    """
    获取浮点数函数
    :param msg: 
    :param allow_zero: 
    :return: 
    """
    x = None
    while x is None:
        try:
            x = float(input(msg))
            if not allow_zero and abs(x) < sys.float_info.epsilon:
                print('zero is not allowed')
                x = None
        except ValueError as err:
            print(err)
    return x


print('ax\N{SUPERSCRIPT TWO} + bx + c = 0')
a = get_float("Enter a:", False)
b = get_float("Enter b:", True)
c = get_float("Enter c:", True)

x1 = None
x2 = None
discriminant = (b ** 2) - (4 * a * c)
if discriminant == 0:
    x1 = -(b / (2 * a))
    print('x1=x2=%s' % x1)
else:
    if discriminant > 0:
        root = math.sqrt(discriminant)
    else:
        root = cmath.sqrt(discriminant)
    x1 = (-b + root) / (2 * a)
    x2 = (-b - root) / (2 * a)
print('%sx\N{SUPERSCRIPT TWO} + %sx + %s = 0' % (a, b, c))
print('x1=%s' % x1)
print('x2=%s' % x2)
